import java.util.Objects;
import java.util.Stack;

public class MinStack {
        private Stack<Integer> stack;
        private Stack<Integer> minStack;
        public MinStack() {
            stack = new Stack<>();
            minStack = new Stack<>();
        }

        public void push(int val) {
            if (stack.empty()) {
                stack.push(val);
                minStack.push(val);
            }
           stack.push(val);
            if (val <= minStack.peek()) {
                minStack.push(val);
            }
        }

        public void pop() {
            if (Objects.equals(stack.peek(), minStack.peek())) {
                minStack.pop();
            }
            stack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minStack.pop();
        }
}
